package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ssy.lingxi.member.merchant.handler.annotation.CurrencyTypeAnnotation;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToAreaBOConverter;
import com.ssy.lingxi.member.merchant.model.bo.AreaBO;
import lombok.Data;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

/**
 * 会员分类信息
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-25
 */
@Data
@Entity
@Table(schema = "public", name = "ms_mc_member_classification")
public class MemberClassificationDO implements Serializable {
    private static final long serialVersionUID = -774406475149076551L;

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_classification_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_classification_seq", name="member_classification_seq", allocationSize = 1)
    private Long id;

    /**
     * 上级会员Id
     */
    @Column
    private Long memberId;

    /**
     * 下级会员Id
     */
    @Column
    private Long roleId;

    /**
     * 一对一双向关联会员关系
     */
    @JsonBackReference
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name="relation_id", referencedColumnName="id")
    private MemberRelationDO relation;

    /**
     * 会员编码
     */
    @Column(columnDefinition = "varchar(20)")
    private String code;

    /**
     * 合作关系枚举，定义在MemberPartnerTypeEnum中
     */
    @Column
    private Integer partnerType;

    /**
     * 单次采购最大金额
     */
    @Column(columnDefinition = "numeric")
    private BigDecimal maxAmount;

    /**
     * 适用区域
     */
    @Convert(converter = JpaJsonToAreaBOConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<AreaBO> areas;

    /**
     * 一对多单向关联主营品类
     */
    @OneToMany(cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    @JoinColumn(name = "business_category_id", referencedColumnName="id")
    private Set<MemberBusinessCategoryDO> categories;

    /**
     * 币别枚举，定义在CurrencyTypeEnum中
     */
    @Column
    private Integer currencyType;

    /**
     * 备注
     */
    @Column
    private String remark;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public MemberRelationDO getRelation() {
        return relation;
    }

    public void setRelation(MemberRelationDO relation) {
        this.relation = relation;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Integer getPartnerType() {
        return partnerType;
    }

    public void setPartnerType(Integer partnerType) {
        this.partnerType = partnerType;
    }

    public BigDecimal getMaxAmount() {
        return maxAmount;
    }

    public void setMaxAmount(BigDecimal maxAmount) {
        this.maxAmount = maxAmount;
    }

    public List<AreaBO> getAreas() {
        return areas;
    }

    public void setAreas(List<AreaBO> areas) {
        this.areas = areas;
    }

    public Set<MemberBusinessCategoryDO> getCategories() {
        return categories;
    }

    public void setCategories(Set<MemberBusinessCategoryDO> categories) {
        this.categories = categories;
    }
}
